package com.lagouedu.pojo;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author: chenhy
 * @Description:请求对象
 * @Date: Create in 12:01 上午 2020/3/26
 */
public class Request {

  //访问资源的URL
  private String url;

  //请求的方式GET/POST
  private String methodType;

  //初始化Request方法
  public Request(InputStream ins) throws IOException {
    int count = 0;
    while (count == 0) {
      count = ins.available();
    }
    byte[] bytes = new byte[count];
    ins.read(bytes);
    String inputStr = new String(bytes);
    //先按行切割
    String[] lineStr = inputStr.split("\n");
    //再对第一行进行处理，拿到请求方法和URL
    String[] blockStr = lineStr[0].split(" ");
    this.methodType = blockStr[0];
    this.url = blockStr[1];

    System.out.println("========methodType: " + methodType);
    System.out.println("========url: " + url);
  }

  public String getUrl() {
    return url;
  }

  public void setUrl(String url) {
    this.url = url;
  }

  public String getMethodType() {
    return methodType;
  }

  public void setMethodType(String methodType) {
    this.methodType = methodType;
  }
}
